#!/usr/bin/python -i

from ceorModule import *
import time

from optparse import OptionParser
parser = OptionParser("usage:  %prog [options] arg1 ")
parser.add_option("-f", "--iniFile", dest="iniFile")

#class GasTime:
#  def __init__(self, gas, timeDim=1):
#    self.timeDim = timeDim
#    self.time  = np.zeros(self.timeDim)
#    self.Ekint = np.zeros(self.timeDim)
#    self.Epott = np.zeros(self.timeDim)
#    self.Etott = np.zeros(self.timeDim)
#    self.fluxt = np.zeros(self.timeDim)
#    # could be pressure
#    self.time_i = 0
#    
#    #Micro states in time
#    self.xt  = np.zeros([gas.N, timeDim])
#    self.yt  = np.zeros([gas.N, timeDim])
#    self.vxt = np.zeros([gas.N, timeDim])
#    self.vyt = np.zeros([gas.N, timeDim])
#    self.fxt = np.zeros([gas.N, timeDim])
#    self.fyt = np.zeros([gas.N, timeDim])
#    
#  def saveState(self, gas, step, dt):
#    self.time[time_i]  = step*dt
#    self.Ekint[time_i] = gas.Ekin
#    self.Epott[time_i] = gas.Epot
#    self.Etott[time_i] = gas.Etot
#    self.time_i = self.time_i + 1
#  
#  def saveMicroState(self, gas, step, dt):
#    for j in range(gas.N):
#      xt[j][time_i]  = gas.particle[j].x_new
#      yt[j][time_i]  = gas.particle[j].y_new
#      vxt[j][time_i] = gas.particle[j].vx_new
#      vyt[j][time_i] = gas.particle[j].vy_new
#      fxt[j][time_i] = gas.particle[j].fx_new
#      fyt[j][time_i] = gas.particle[j].fy_new

################ MAIN ################
## Is a 2-D box with lenght Lx Ly
if __name__ == "__main__":
  # And God says...
  (options, args) = parser.parse_args()
  gas = Gas2D(iniFile=str(options.iniFile))
  gasini = gas
  gas.plot()
  
  tic = time.time()
  sigma = 1.0
  eps = 1.0
  total_time = 1000
  ttime = range(total_time)
  dt = 0.001
  timeDim = 200 
  gasTime = GasTime(gas,timeDim)
  taux = total_time/timeDim
  
  gas.calculateForces(eps, sigma)
  for i in ttime:
    gas.save_old() # fx_old=fx_new
    gas.stepPosition(dt) # input old variables = > output x_new
    gas.inBox()
    gas.calculateForces(eps, sigma)
    gas.stepVelocity(dt)
    if i % taux == 0:
      gasTime.saveState(gas,i,dt)
      #print i, total_time,timeDim
  gas.plot()
  toc = time.time()
  print toc-tic

